Function.RegisterNamespace("System.Web");

System.Web.Style=new function(){
    // Public Methods    
    this.AddClass=function(node,name){
        if(Object.IsType(Array,name)){
            for(var i=0;i<name.length;i++)this.AddClass(node,name[i]);
            return;
        }
        if(name==undefined||!Object.IsType(Function,name.toString))throw new Error("System.Web.Style.AddClass: 'name' must be convertible to String.");
        if(!node||this.HasClass(node,name))return;
        if(!node.className)node.className=name;
        else node.className=[node.className,name].join(' ');
    };

    this.GetOpacity=function(node){
        if(node==undefined||!node.nodeType)return null;
        if(typeof(node.style.opacity)!="undefined")return parseInt(node.style.opacity);
        if(typeof(node.style.MozOpacity)!="undefined")return parseInt(node.style.MozOpacity);
        if(typeof(node.style.WebkitOpacity)!="undefined")return parseInt(node.style.WebkitOpacity);
        if(typeof(node.style.filter)!="undefined")return parseInt(node.style.filter.split("opacity=")[1]||100)/100;
    };

    this.GetStyle=function(node,name,pseudo){
        if(node==undefined||!node.nodeType)return null;
        var window=Object.Global();
        if(window.getComputedStyle){
            var computedStyle=window.getComputedStyle(node,pseudo||null);
            if(computedStyle)return computedStyle.getPropertyValue(name);
        }
        if(node.currentStyle)return node.currentStyle[name];
        if(node.style)return node.style[name];
        return '';
    };

    this.HasClass=function(node,name){
        if(name==undefined||!Object.IsType(Function,name.toString))throw new Error("System.Web.Style.HasClass: 'name' must be convertible to String.");
        if(!node||!node.className)return false;
        return new RegExp(String.Format("\\b{0}\\b",name)).test(node&&node.className);
    };

    this.RemoveClass=function(node,name){
        if(Object.IsType(Array,name)){
            for(var i=0;i<name.length;i++)this.RemoveClass(node,name[i]);
            return;
        }
        if(name==undefined||!Object.IsType(Function,name.toString))throw new Error("System.Web.Style.RemoveClass: 'name' must be convertible to String.");
        if(!node||!this.HasClass(node,name))return;
        var className=String.Trim(node.className.replace(new RegExp(String.Format("\\s*\\b{0}\\b\\s*",name),'g'),' '));
        node.className=className;
        if(!className&&Object.IsType(Function,node.removeAttribute))node.removeAttribute("class");
    };

    this.SetOpacity=function(node,opacity){
        if(!Object.IsType(Number,opacity))throw new Error("System.Web.Style.SetOpacity: 'opacity' must be a valid Number.");
        if(opacity<0||opacity>1)throw new Error("System.Web.Style.SetOpacity: 'opacity' must be a decimal value between 0 and 1.");
        Object.Set(node,{style:{
            opacity:opacity,
            MozOpacity:opacity,
            WebkitOpacity:opacity,
            filter:String.Format("alpha(opacity={0})",opacity*100)
        }});
    };

    this.SetStyle=function(node,styles){
        if(!node)return;
        return Object.Set(node,{style:styles||{}});
    };
};